﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using portfolio.Common;

namespace portfolio
{
    public partial class _Default : Page
    {
        private string LoadedControlName
        {
            get
            {
                return (string)ViewState[SessionConstants.LoadedControlName] ?? StringConstants.DefaultContentControl;
            }

            set
            {
                ViewState[SessionConstants.LoadedControlName] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadContent();
        }

        protected void ViewChooser_TabClick(object sender, RadTabStripEventArgs e)
        {
            UpdateSelectedView();
        }

        protected void UpdateSelectedView()
        {
            string selectedControl = ViewChooser.SelectedTab.Value;
            if (selectedControl != LoadedControlName)
            {
                LoadedControlName = selectedControl;
                Session[SessionConstants.SelectedTabStrip] = LoadedControlName;
                LoadContent();
            }
        }

        private void LoadContent()
        {
            var control = LoadControl(StringConstants.ViewsFolder + LoadedControlName);
            control.ID = StringConstants.GenericControlID;
            Content.Controls.Clear();
            Content.Controls.Add(control);
        }
    }
}